﻿namespace NuGetCop.MSBuild.Tasks
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Diagnostics.Contracts;

    internal sealed class NuGetPackageCheckResult : INuGetPackageCheckResult
    {
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private readonly ReadOnlyCollection<string> errors;

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private readonly ReadOnlyCollection<INuGetPackageReference> relatedPackages;

        public NuGetPackageCheckResult(
            IList<INuGetPackageReference> relatedPackages,
            IList<string> errors)
        {
            Contract.Requires(relatedPackages != null);
            Contract.Requires(errors != null);

            this.relatedPackages = new ReadOnlyCollection<INuGetPackageReference>(relatedPackages);
            this.errors = new ReadOnlyCollection<string>(errors);
        }

        public ReadOnlyCollection<INuGetPackageReference> RelatedPackages
        {
            [DebuggerStepThrough]
            get { return relatedPackages; }
        }

        public ReadOnlyCollection<string> Errors
        {
            [DebuggerStepThrough]
            get { return errors; }
        }

        [ContractInvariantMethod]
        private void ObjectInvariant()
        {
            Contract.Invariant(relatedPackages != null);
            Contract.Invariant(errors != null);
        }
    }
}